#!/usr/bin/env python
import euclid

class NodePoint( object ):
    __slots__ = ['radius', 'pos']
    def __init__(self, radius, pos):
        self.radius = radius
        self.pos = pos
        
        assert type( self.pos ) in ( euclid.Point2, euclid.Point3, euclid.Vector2, euclid.Vector3 )
        
        
    def arrived( self, pos ):
        assert type( self.pos ) in ( euclid.Point2, euclid.Point3, euclid.Vector2, euclid.Vector3 )
        return ( pos - self.pos ).magnitude_squared() < self.radius**2

class Path(object):
    __slots__ = ['nodes', 'looped', 'index']
    
    def __init__(self, looped, nodes=None):
        if not nodes: nodes = []
        self.looped = looped
        self.nodes = nodes
        self.index = 0
        
    def addNode( self, node ):
        self.nodes.append( node )

    def current( self ):
        return self.nodes[ self.index ]
    
    def advance(self):
        self.index += 1
        if self.index >= len( self.nodes ) - 1 and self.looped:
            self.index = 0
        elif self.index >= len( self.nodes ) - 1:
            self.index = len( self.nodes ) - 1
    
    def finished( self ):
        if self.looped:
            return False
        elif self.index < len( self.nodes ):
            return False
        else:
            return True
        
    